#ifndef CAMERA_H
#define CAMERA_H
#define WIN32_LEAN_AND_MEAN
#include <QObject>
#include <QtNetwork>

#include <winsock2.h>
#include <Windows.h>
#include <mswsock.h>
#include "ice_com_type.h"
#include "ice_base_type.h"
#include "ice_vdc_config.h"
#include "ice_vdc_result.h"
#include "ice_vlpr_result.h"
#include "sys/stat.h"
#include "stdlib.h"
#include <stdio.h>
#include "systemfile.h"
#include "yb_led.h"

#define REQUEST_OPEN 0x5065 //起杠
#define REQUEST_OPEN_RES 0x5066
#define REQUEST_PHOTO 0x1033
#define REQUEST_PHOTO_RES 0x1034  //无抓怕图片
#define REQUEST_RS485   0x1037
#define REQUEST_RS485_RES 0x1038
#define REQUEST_NUMBER_RES 0x2002
#define REQUEST_TARGET 0x1005   //补拍
#define REQUEST_TARGET_RES 0x1006
#define LINK_TIME   10000   //最大空闲时间
#define LONGSOCKET_TIME   5000   //最大空闲时间
#define INFO_ADDR   2
#define TIME_ADDR   1

//typedef struct displayData_t
//{
//    QString audioStr;
//    QString DispelayStr[4];
//}displayData_t;
class camera : public QObject
{
    Q_OBJECT
public:
    explicit camera(QObject *parent = 0);
    QTcpSocket *tcp_socket_short;
    QTcpSocket *tcp_socket_long;
    QString camerarIp;
    int request_type;
    QByteArray packHeader_short;
    QByteArray picBuffer_short;
    QByteArray packHeader_long;
    QByteArray picBuffer_long;
    void socket_link(QString ip);
    void socket_short_request(int request);
    void socket_short_request_open(int request);
    void socket_short_send(QByteArray buf);
    void socket_short_display(displayData_t *info);
    void socket_short_syncTime();
    QTimer *link_Timer,*timer_receive;
    bool m_ServerConnected;
    bool n_ServerConnected;
    QDateTime curentTime;
    QMutex mutex;
private:
     int  short_fd;
     struct sockaddr_in sd_addr;
signals:
    void carNumberRecEnd(QString carNum,QPixmap *pic);
    void CameraLongConnect();
public slots:
    void socket_short_rec();
    void socket_short_connected();
    void socket_short_desconnected();
    void socket_long_send();
    void socket_long_rec();
    void socket_long_connected();
    void socket_long_desconnected();
    void displayError(QAbstractSocket::SocketError);
    void displayshortError(QAbstractSocket::SocketError);
    void longsocket_in(QString);
    void linkTimerOver();
    void CameraRecive();
};

#endif // CAMERA_H
